import requests

# url='http://fy.iciba.com/ajax.php?a=fy'
#
# headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'}
#
# data2={
#   'f': 'auto',
#   't': 'auto',
#   'w': '好好学习'
# }
#
# r=requests.post(url,headers=headers,data=data2)
# print(r.content)

class FanYi:
    def __init__(self,word):
        self.url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
        self.headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'}
        self.word=word
        self.data= {
            'i': self.word,
            'from': 'AUTO',
            'to': 'AUTO',
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': '16062740908141',
            'sign': 'c9c8f0a0cf517739d62558e29b37186c',
            'lts': '1606274090814',
            'bv': '02edb5d6c6ac4286cd4393133e5aab14',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_REALTlME'
        }
    #爬取数据的函数
    def get_data(self):
        data=requests.post(self.url,headers=self.headers,data=self.data)
        return data.content.decode()

F=FanYi('我')
print(F.get_data())


FF=FanYi('饼干')
print(FF.get_data())
